﻿using Microsoft.AspNetCore.Mvc;
using Zhp.Api.Attributes;
using Zhp.IService.Sys;
using Zhp.Model.Common;
using Zhp.Model.Sys;

namespace Zhp.Api.Controllers.Sys
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiGroup(GroupName = ApiGroupEnum.Sys)]
    [SeedMenu(MenuGroup = ApiGroupEnum.Sys, Name = "用户管理", Order = 4, RouterName = "user", WebFilePath = "sys/user/index", Icon = "user")]
    public class SysUserController : ControllerBase
    {
        protected readonly ISysUserService _sysUserSvc;

        public SysUserController(ISysUserService SysUser)
        {
            _sysUserSvc = SysUser;
        }

        [SeedList("用户列表", "用户管理", ApiGroupEnum.Sys)]
        [HttpPost]
        public async Task<PageRet<UserModel>> Index(UserQuery query)
        {
            var list = await _sysUserSvc.GetUser(query);
            
            return new PageRet<UserModel>
            {
                DataList = list,
                TotalCount = query.TotalCount,
            };
        }

        [SeedButton("新增", "用户列表", "用户管理", ApiGroupEnum.Sys)]
        [HttpPost]
        public async Task<bool> Create(UserCreate user)
        {
            return await _sysUserSvc.Create(user);
        }

        [SeedButton("修改", "用户列表", "用户管理", ApiGroupEnum.Sys)]
        [HttpPut]
        public async Task<bool> Update(UserCreate user)
        {
            return await _sysUserSvc.Update(user);
        }

        [SeedButton("删除", "用户列表", "用户管理", ApiGroupEnum.Sys)]
        [HttpDelete("{id}")]
        public async Task<bool> Delete(string id)
        {
            return await _sysUserSvc.Delete(id);
        }

        [SeedButton("重置密码", "用户列表", "用户管理", ApiGroupEnum.Sys)]
        [HttpGet("{id}")]
        public async Task<bool> ResetPassword(long id)
        {
            return await _sysUserSvc.ResetPassword(id);
        }
    }
}
